package com.quarantine.web;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.quarantine.model.announcement;
import com.quarantine.service.AnnouncementManager;
import com.quarantine.web.CrudActionSupport;

@Namespace("/base")
public class AnnouncementAction extends CrudActionSupport<announcement> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private announcement entity;
	private AnnouncementManager announcement;
	private String id;
	private List<announcement> announcementList;
	/**
	 * 分頁用
	 */
	private int currentpage;
	private int pageNo;
	public static final int pageSize = 20;
	private int prePage;
	private long totalPages;
	private int nextPage;
	private long allsize;
	
    
	@Override
	public announcement getModel() {
		// TODO Auto-generated method stub
		return null;
	}
/**
 * 列出公告列表 
 */
	@Override
	public String list() throws Exception {
		int pageSize = 10;
		Page<announcement> page = new Page<announcement>();
		page.setAutoCount(true);
		page.setPageNo(currentpage);
		page.setPageSize(pageSize);
	    announcement.getList(page);
		setAnnouncementList(page.getResult());
		pageNo = page.getPageNo();
		prePage = page.getPrePage();
		nextPage = page.getNextPage();
		totalPages = page.getTotalPages();
		if(totalPages==0){
			
			pageNo=0;
		}
		allsize = page.getTotalCount();
		return "list";
	}
	/*
	 * 根据id获取对象并把点击率加一
	 */
	public String show() {
		Integer resetrate;
		entity = announcement.getById(id);
		
		entity.setEditTime(entity.getEditTime());
		System.out.println(entity.getClickrate());
		resetrate = 1 + entity.getClickrate();
		entity.setClickrate(resetrate);
		announcement.save(entity);
		return "detail"; // 待改
	}
	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

 
 

	@Override
	protected void prepareModel() throws Exception {
		if (StringUtils.isEmpty(id)) {
			entity = new announcement();
		} else {
			entity = announcement.getById(id);
		}
		
	}
 
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public int getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPrePage() {
		return prePage;
	}
	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}
	public long getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(long totalPages) {
		this.totalPages = totalPages;
	}
	public int getNextPage() {
		return nextPage;
	}
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	public long getAllsize() {
		return allsize;
	}
	public void setAllsize(long allsize) {
		this.allsize = allsize;
	}
	public announcement getEntity() {
		return entity;
	}

	public void setEntity(announcement entity) {
		this.entity = entity;
	}

	public AnnouncementManager getAnnouncement() {
		return announcement;
	}
	@Autowired
	public void setAnnouncement(AnnouncementManager announcement) {
		this.announcement = announcement;
	}
	public List<announcement> getAnnouncementList() {
		return announcementList;
	}
	public void setAnnouncementList(List<announcement> announcementList) {
		this.announcementList = announcementList;
	}
	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
